<template>
  <div>
    <div>
      <el-button type="success" @click="goAdd">添加职位</el-button>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <!-- <el-table-column
        prop="pid"
        label="id"
        width="180">
      </el-table-column>-->
      <el-table-column prop="pname" label="公司名称" width="180"></el-table-column>
      <el-table-column prop="ptype" label="招聘职位"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="goUpdate(scope.row)">修改</el-button>
          <el-button type="danger" size="small" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :current-page="page"
      :total="total"
      :page-size="pageSize"
      @current-change="goPage">
    </el-pagination>
  </div>
</template>
  <script>
export default {
  data() {
    return {
      tableData: [],
      page: 1,
      total: 100,
      pageSize: 8,
    };
  },
  created() {
    this.getDate();
  },
  methods: {
    getDate() {
      this.$http({
        url: "/admin/position/getAll",
        params: {
          page: this.page,
          pageSize:this.pageSize
        }
      }).then((res) => {
        this.tableData = res;
      });
    },
    goPage(page){
      this.page = page
      this.getDate()
    },
    goAdd() {
      this.$router.push({
        path: "/job/add",
      });
    },
    goUpdate(item) {
      sessionStorage.jobs = JSON.stringify(item);
      this.$router.push({
        path: "/job/update",
      });
    },
    del(item) {
      console.log(item);
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http({
            url: "/admin/position/Delete",
            params: {
              pId: item.pid,
            },
          }).then((res) => {
            console.log(res);
            this.getDate();
            this.$message({
              message: "删除成功",
              type: res.code == 200 ? "error" : "success",
            });
            if (res.code == 200) {
              this.getDate();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-table{
  margin-bottom: 20px;
}
</style>